package com.itheima.mapper;

import com.github.pagehelper.Page;
import com.itheima.pojo.Emp;
import com.itheima.pojo.EmpQueryParam;
import com.itheima.pojo.JobCountData;
import org.apache.ibatis.annotations.*;

import java.util.List;
import java.util.Map;


@Mapper
public interface EmpMapper {

    Page<Emp> list(EmpQueryParam empQueryParam);
    /**
     * 批量删除员工
     * @param ids
     * @return
     */
    int deleteById(@Param("ids") List<Integer> ids);

    /**
     * 新增员工
     * @param emp
     * @return
     */
    @Options(useGeneratedKeys = true, keyProperty = "id")
    @Insert("insert into emp(username, name, gender, phone, job, salary, image, entry_date, dept_id, create_time, update_time) " +
            "values (#{username},#{name},#{gender},#{phone},#{job},#{salary},#{image},#{entryDate},#{deptId},#{createTime},#{updateTime})")
    int insert(Emp emp);

    /**
     * 查询全部员工信息
     * @return
     */
    List<Emp> select();
    /**
     * 根据id查询员工
     * @param id
     * @return
     * 第一种方法
     */
    /*Emp selectById(Integer id);*/

    /**
     * 根据id查询员工信息
     * @param id
     * @return
     * 第二种方法
     */
    Emp getById(Integer id);

    /**
     * 修改员工信息
     * @param emp
     * @return
     */
    int updateById(Emp emp);

    /**
     * 查询员工职位数据
     * @return
     */
    @Select("""

            select
               case job when '1' then '班主任'
                when 2 then '讲师'
                when 3 then '学工主管'
                when 4 then '教研主管'
                when 5 then '咨询师'
                else '其他'
                end as jobName,
             count(*) as num
         from emp group by job 
         order by num
                
    """)
    List<JobCountData> countEmpJobData();

    /**
     * 查询员工性别数据
     * @return
     */
    @Select("select if(gender = 1 ,'男','女') as name,count(*) as value from emp group by gender")
    List<Map<String,Object>> getEmpGenderData();

    Emp selectByUsernameAndPassword(Emp emp);
}
